package com.letu.mq.producer;

import com.alibaba.fastjson.JSONObject;
import com.letu.cache.repository.CachePlusOps;
import com.letu.mq.event.ProducerEvent;
import com.letu.mq.model.MySimpleMessage;
import com.letu.mq.util.MessageKeyUtil;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

/**
 * 多功能串联 类型发送
 */
@Component
public class OrderBusinPointProducer implements BaseProducerService {
    @Autowired
    private ProducerEvent producerEvent;

//    @Value("${rocketmq.consumer.orderConsumer}")
    private String orderConsumer;

    @Autowired
    private CachePlusOps cachePlusOps;

    @Override
    public void send(Object obj) {
        //推送到rocket mq
        String tag = MessageKeyUtil.getPointNameInvok(obj);
        MySimpleMessage mySimpleMessage = new MySimpleMessage();
        mySimpleMessage.setPayload(obj);
        Map<String, Object> headers = MessageKeyUtil.getHeaderMapInvok(obj);
        if (headers == null) {
            headers = new HashMap<>();
        }
        headers.put("tag", tag);
        mySimpleMessage.setHeaders(headers);
        mySimpleMessage.setTopic(orderConsumer + ":" + tag);
        producerEvent.orderSend(mySimpleMessage);
    }
}
